package com.kaifamiao.loader;

import java.lang.reflect.Constructor;

public class ClassForName {

    public static void main(String[] args) throws Exception {

        String path = "D:/kaifamiao/codes/java-advanced/classloader/bytecodes";
        final ClassLoader loader = new MyClassLoader( path );

        String name = "com.kaifamiao.Monkey";
        // 当 initialize 为 true 时表示加载指定类并完成该类的初始化
        boolean initialize = false;
        // 用 loader 加载 name 类 并根据 initialize 确定是否初始化该类
        Class<?> c = Class.forName( name, initialize, loader );

        System.out.println( c.getName() );
        System.out.println( c.getSuperclass().getName() );

        System.out.println( "- ".repeat(30) );

        Constructor<?> con = c.getConstructor( String.class );
        Object x = con.newInstance( "孙悟空" );
        System.out.println( x );

    }

}
